3e2a30
@@ -30,10 +30,12 @@
import org.apache.commons.configuration.beanutils.BeanFactory;
 import org.apache.commons.configuration.beanutils.BeanHelper;
 import org.apache.commons.configuration.beanutils.DefaultBeanFactory;
 import org.apache.commons.configuration.beanutils.XMLBeanDeclaration;
+import org.apache.commons.configuration.event.ConfigurationErrorListener;
 import org.apache.commons.configuration.tree.ConfigurationNode;
 import org.apache.commons.configuration.tree.DefaultExpressionEngine;
 import org.apache.commons.configuration.tree.OverrideCombiner;
 import org.apache.commons.configuration.tree.UnionCombiner;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * <p>
@@ -120,7 +122,11 @@
import org.apache.commons.configuration.tree.UnionCombiner;
  * <tr>
  * <td valign="top"><code>config-optional</code></td>
  * <td>Declares a configuration as optional. This means that errors that occur
- * when creating the configuration are silently ignored.</td>
+ * when creating the configuration are ignored. (However
+ * <code>{@link ConfigurationErrorListener}</code>s registered at the builder
+ * instance will get notified about this error: they receive an event of type
+ * <code>EVENT_ERR_LOAD_OPTIONAL</code>. The key property of this event contains
+ * the name of the optional configuration source that caused this problem.)</td>
  * </tr>
  * </table>
  * </p>
@@ -178,6 +184,12 @@
public class DefaultConfigurationBuilder extends XMLConfiguration implements
             .getName()
             + "/ADDITIONAL_CONFIG";
 
+    /**
+     * Constant for the type of error events caused by optional configurations
+     * that cannot be loaded.
+     */
+    public static final int EVENT_ERR_LOAD_OPTIONAL = 51;
+
     /** Constant for the name of the configuration bean factory. */
     static final String CONFIG_BEAN_FACTORY_NAME = DefaultConfigurationBuilder.class
             .getName()
@@ -329,6 +341,8 @@
public class DefaultConfigurationBuilder extends XMLConfiguration implements
         super();
         providers = new HashMap();
         registerDefaultProviders();
+        setLogger(LogFactory.getLog(getClass()));
+        addErrorLogListener();  // log errors per default
     }
 
     /**
@@ -1061,6 +1075,12 @@
public class DefaultConfigurationBuilder extends XMLConfiguration implements
                 }
                 else
                 {
+                    // Notify registered error listeners
+                    decl.getConfigurationBuilder().fireError(
+                            EVENT_ERR_LOAD_OPTIONAL,
+                            decl.getConfiguration().getString(ATTR_NAME), null,
+                            ex);
+
                     if (decl.isForceCreate())
                     {
                         try
